package cn.itcast.mq.listener;

import netscape.security.ForbiddenTargetException;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * - @author by 姜暄煊
 * - @Date 11.22
 * - @Description
 */
@Component
public class SpringRabbitListener {
    //注解获取队列

   /* @RabbitListener(queues = "simple.queue")
    public void listenSimpleQueueMessage(String message) throws InterruptedException {
        System.out.println("SPRING 消费者1接收到的消息:" + message);
        Thread.sleep(20);
    }

    @RabbitListener(queues = "simple.queue")
    public void listenSimpleQueueMessage1(String message) throws InterruptedException {
        System.err.println("SPRING 消费者2接收到的消息:" + message);
        Thread.sleep(200);
    }

    @RabbitListener(queues = "fanout,queue1")
    public void listFanoutQueue1(String msg) {
        System.out.println("消费者一接收到fanout1消息" + msg);
    }
    @RabbitListener(queues = "fanout,queue2")
    public void listFanoutQueue2(String msg) {
        System.out.println("消费者二接收到fanout2消息" + msg);
    }*/

   /* @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue1"),
            exchange = @Exchange(name = "itcast.direct",type = ExchangeTypes.DIRECT),
            key = {"red","biue"}

    ))
    public void listDirectQueue1(String msg) {
        System.out.println("消费者接收到direct.queue1的消息"+ msg);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue2"),
            exchange = @Exchange(name = "itcast.direct",type = ExchangeTypes.DIRECT),
            key = {"red","yellow"}

    ))
    public void listDirectQueue2(String msg) {
        System.out.println("消费者接收到direct.queue2的消息"+ msg);
    }
*/
        @RabbitListener(bindings = @QueueBinding(
                value = @Queue(name="topic.queue1"),
                exchange = @Exchange(value = "itcast.topic",type = ExchangeTypes.TOPIC),
                key = "chin.#"
        ))
    public void listenTopicQueue1(String msg) {
            System.out.println("消费者1收到:" + msg);
        }

  @RabbitListener(bindings = @QueueBinding(
                value = @Queue(name="topic.queue2"),
                exchange = @Exchange(value = "itcast.topic",type = ExchangeTypes.TOPIC),
                key = "chin.#"
        ))
    public void listenTopicQueue2(String msg) {
            System.out.println("消费者2收到:" + msg);
        }


}
